//
//  ST_TianLogger.swift
//  btvideo
//
//  Created by mac on 2021/4/9.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import UIKit


enum TIAN_LOG_FILE_ENUM:CaseIterable{
    case 语音房
    case 单聊
    
    var fileName:String{
        switch self {
        case .语音房:
            return "voice_chat_group_log.text"
        case .单聊:
            return "single_chat_log.text"
        }
    }
}




struct TianDebugLoger: TextOutputStream {

    let type:TIAN_LOG_FILE_ENUM
    init(type:TIAN_LOG_FILE_ENUM) {
        self.type = type
    }
    
    func write(_ string: String) {
        
        #if DEBUG
        let fm = FileManager.default
        let log = fm.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent(self.type.fileName)
        if let handle = try? FileHandle(forWritingTo: log) {
            handle.seekToEndOfFile()
            handle.write(string.data(using: .utf8)!)
            handle.closeFile()
        } else {
            try? string.data(using: .utf8)?.write(to: log)
        }
        #endif
    }
}





//MARK: -
var todayPayLogger = TIANPayLog()

struct TIANPayLog: TextOutputStream {

    func write(_ string: String) {
        
        #if DEBUG
        let fm = FileManager.default
        let log = fm.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("tian_pay.txt")
        if let handle = try? FileHandle(forWritingTo: log) {
            handle.seekToEndOfFile()
            handle.write(string.data(using: .utf8)!)
            handle.closeFile()
        } else {
            try? string.data(using: .utf8)?.write(to: log)
        }
        #endif
        
    }
}



var todayMatchingLogger = MatchingTalkLog()



struct MatchingTalkLog: TextOutputStream {

    func write(_ string: String) {
        
        #if DEBUG
        let fm = FileManager.default
        let log = fm.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("MatchingTalkLog.txt")
        if let handle = try? FileHandle(forWritingTo: log) {
            handle.seekToEndOfFile()
            handle.write(string.data(using: .utf8)!)
            handle.closeFile()
        } else {
            try? string.data(using: .utf8)?.write(to: log)
        }
        #endif
        
    }
}


